#include <public/version.h>
#include <public/memory.h>
-int hvm_enabled = 0;
+int hvm_enabled;
-unsigned int opt_hvm_debug_level = 0;
+unsigned int opt_hvm_debug_level;
integer_param("hvm_debug", opt_hvm_debug_level);
struct hvm_function_table hvm_funcs;
+/* I/O permission bitmap is globally shared by all HVM guests. */
+char __attribute__ ((__section__ (".bss.page_aligned")))
+ hvm_io_bitmap[3*PAGE_SIZE];
+
+void hvm_enable(void)
+{
+ if ( hvm_enabled )
+ return;
+
+ /*
+ * Allow direct access to the PC debug port (it is often used for I/O
+ * delays, but the vmexits simply slow things down).
+ */
+ memset(hvm_io_bitmap, ~0, sizeof(hvm_io_bitmap));
+ clear_bit(0x80, hvm_io_bitmap);
+
+ hvm_enabled = 1;
+}
+
void hvm_stts(struct vcpu *v)
{
/* FPU state already dirty? Then no need to setup_fpu() lazily. */
hvm_funcs.init_ap_context = svm_init_ap_context;
hvm_funcs.init_hypercall_page = svm_init_hypercall_page;
- hvm_enabled = 1;
+ hvm_enable();
return 1;
}
vmcb->cr_intercepts = ~(CR_INTERCEPT_CR2_READ | CR_INTERCEPT_CR2_WRITE);
/* I/O and MSR permission bitmaps. */
- arch_svm->iopm = alloc_xenheap_pages(get_order_from_bytes(IOPM_SIZE));
arch_svm->msrpm = alloc_xenheap_pages(get_order_from_bytes(MSRPM_SIZE));
- if ( (arch_svm->iopm == NULL) || (arch_svm->msrpm == NULL) )
- {
- free_xenheap_pages(arch_svm->iopm, get_order_from_bytes(IOPM_SIZE));
- free_xenheap_pages(arch_svm->msrpm, get_order_from_bytes(MSRPM_SIZE));
+ if ( arch_svm->msrpm == NULL )
return -ENOMEM;
- }
- memset(arch_svm->iopm, 0xff, IOPM_SIZE);
- clear_bit(PC_DEBUG_PORT, arch_svm->iopm);
memset(arch_svm->msrpm, 0xff, MSRPM_SIZE);
- vmcb->iopm_base_pa = (u64)virt_to_maddr(arch_svm->iopm);
vmcb->msrpm_base_pa = (u64)virt_to_maddr(arch_svm->msrpm);
+ vmcb->iopm_base_pa = (u64)virt_to_maddr(hvm_io_bitmap);
/* Virtualise EFLAGS.IF and LAPIC TPR (CR8). */
vmcb->vintr.fields.intr_masking = 1;
if ( arch_svm->vmcb != NULL )
free_vmcb(arch_svm->vmcb);
- if ( arch_svm->iopm != NULL )
- {
- free_xenheap_pages(
- arch_svm->iopm, get_order_from_bytes(IOPM_SIZE));
- arch_svm->iopm = NULL;
- }
-
if ( arch_svm->msrpm != NULL )
{
free_xenheap_pages(
CPU_BASED_INVDPG_EXITING | \
CPU_BASED_MWAIT_EXITING | \
CPU_BASED_MOV_DR_EXITING | \
- CPU_BASED_UNCOND_IO_EXITING | \
+ CPU_BASED_ACTIVATE_IO_BITMAP | \
CPU_BASED_USE_TSC_OFFSETING )
/* Basic flags for VM-Exit controls. */
__vmwrite(CPU_BASED_VM_EXEC_CONTROL, vmx_cpu_based_exec_control);
v->arch.hvm_vcpu.u.vmx.exec_control = vmx_cpu_based_exec_control;
+ /* I/O access bitmap. */
+ __vmwrite(IO_BITMAP_A, virt_to_maddr(hvm_io_bitmap));
+ __vmwrite(IO_BITMAP_B, virt_to_maddr(hvm_io_bitmap + PAGE_SIZE));
+
/* Host data selectors. */
__vmwrite(HOST_SS_SELECTOR, __HYPERVISOR_DS);
__vmwrite(HOST_DS_SELECTOR, __HYPERVISOR_DS);
/* Setup HVM interfaces */
static void vmx_setup_hvm_funcs(void)
{
- if ( hvm_enabled )
- return;
-
hvm_funcs.disable = stop_vmx;
hvm_funcs.vcpu_initialise = vmx_vcpu_initialise;
vmx_setup_hvm_funcs();
- hvm_enabled = 1;
+ hvm_enable();
return 1;
}
EXCEPTION_BITMAP_BP )
#endif
-#define PC_DEBUG_PORT 0x80
-
#define VMX_DELIVER_NO_ERROR_CODE -1
#if HVM_DEBUG
#define hvm_get_struct(_h, _p) \
hvm_get_buffer((_h), (char *)(_p), sizeof(*(_p)))
+int hvm_save(struct vcpu*, hvm_domain_context_t *h);
+int hvm_load(struct vcpu*, hvm_domain_context_t *h);
-extern int hvm_save(struct vcpu*, hvm_domain_context_t *h);
-extern int hvm_load(struct vcpu*, hvm_domain_context_t *h);
-
-extern int arch_sethvm_ctxt(struct vcpu *v, struct hvm_domain_context *c);
-extern int arch_gethvm_ctxt(struct vcpu *v, struct hvm_domain_context *c);
+int arch_sethvm_ctxt(struct vcpu *v, struct hvm_domain_context *c);
+int arch_gethvm_ctxt(struct vcpu *v, struct hvm_domain_context *c);
-extern void shpage_init(struct domain *d, shared_iopage_t *sp);
+void shpage_init(struct domain *d, shared_iopage_t *sp);
+extern char hvm_io_bitmap[];
extern int hvm_enabled;
+void hvm_enable(void);
+
int hvm_copy_to_guest_phys(paddr_t paddr, void *buf, int size);
int hvm_copy_from_guest_phys(void *buf, paddr_t paddr, int size);
int hvm_copy_to_guest_virt(unsigned long vaddr, void *buf, int size);
struct arch_svm_struct {
struct vmcb_struct *vmcb;
u64 vmcb_pa;
- u32 *iopm;
u32 *msrpm;
u64 vmexit_tsc; /* tsc read at #VMEXIT. for TSC_OFFSET */
int saved_irq_vector;